package com.ssm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.pojo.Category;
import com.ssm.service.CategoryService;
import com.ssm.util.Page;

public class BaseController {

	 	@Autowired
	 	CategoryService categoryService;
	 	
	    // 显示列表方法
		public void list(ModelMap model,Page page) {
		     PageHelper.offsetPage(page.getStart(), 5);
		     List<Category> list = categoryService.list();
		     model.addAttribute("list", list);
		     int total = (int) new PageInfo<>(list).getTotal();	     
		     page.caculateLast(total);
		}
		// 定位到当前位置方法
		public int nowStart(int nowId) {
			 Page page = new Page();
			 page.caculateLast(nowId);
			 int startId = page.getLast();
		     return startId;	
		}
}
